* wean garmin_gpi from global_opts.codec and cet.
* wean garmin from global_opts.codec and cet.
* remove cet
* don't include deprecated includes, no global codec.
* fix garmin includes
* fix up comment indicating garmin encoding issues.
* fiddle with encoding functions.
* change get_codec signature.
* trailling white space
# SUPPORT
set(SUPPORT
- cet_util.cc
csv_util.cc
fatal.cc
filter_vecs.cc
# HEADERS
set(HEADERS
- cet_util.h
csv_util.h
defs.h
dg-100.h
+++ /dev/null
-/*
-
- Character encoding transformation - utilities
-
- Copyright (C) 2005-2008 Olaf Klein, o.b.klein@gpsbabel.org
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-*/
-
-#include <QByteArray> // for QByteArray
-#include <QDebug> // for QDebug
-#include <QTextCodec> // for QTextCodec
-
-#include "defs.h"
-#include "cet_util.h"
-#include "src/core/logging.h" // for Fatal
-
-
-#define MYNAME "cet_util"
-
-/* gpsbabel additions */
-
-void
-cet_convert_deinit()
-{
- global_opts.codec = nullptr;
-}
-
-void
-cet_convert_init(const QString& cs_name, const int force)
-{
- if ((force != 0) || (global_opts.codec == nullptr)) {
- cet_convert_deinit();
- if (cs_name.isEmpty()) { /* set default us-ascii */
- global_opts.codec = QTextCodec::codecForName(CET_CHARSET_ASCII);
- } else {
- global_opts.codec = QTextCodec::codecForName(CSTR(cs_name));
- }
- if (!global_opts.codec) {
- fatal(FatalMsg() << "Unsupported character set \"" << cs_name << ".");
- }
- }
-}
+++ /dev/null
-/*
-
- Character encoding transformation - utilities header
-
- Copyright (C) 2005-2008 Olaf Klein, o.b.klein@gpsbabel.org
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-*/
-
-#ifndef CET_UTIL_H_INCLUDED_
-#define CET_UTIL_H_INCLUDED_
-
-#include <QString>
-#include "defs.h"
-
-
-/* gpsbabel extensions */
-
-void cet_convert_init(const QString& cs_name, int force);
-void cet_convert_deinit();
-
-#endif // CET_UTIL_H_INCLUDED_
#define CSTR(qstr) ((qstr).toUtf8().constData())
#define CSTRc(qstr) ((qstr).toLatin1().constData())
-#define STRFROMUNICODE(qstr) (global_opts.codec->fromUnicode(qstr).constData())
-#define STRTOUNICODE(cstr) (global_opts.codec->toUnicode(cstr))
/*
* Amazingly, this constant is not specified in the standard...
int smart_icons;
int smart_names;
inifile_t* inifile;
- QTextCodec* codec;
};
extern global_options global_opts;
void* gb_int2ptr(int i);
int gb_ptr2int(const void* p);
+QTextCodec* get_codec(const QByteArray& cs_name);
void list_codecs();
void list_timezones();
QString grapheme_truncate(const QString& input, unsigned int count);
--- /dev/null
+/*
+
+ Character encoding transformation - utilities
+
+ Copyright (C) 2005-2008 Olaf Klein, o.b.klein@gpsbabel.org
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+*/
+
+#include <QByteArray> // for QByteArray
+#include <QDebug> // for QDebug
+#include <QTextCodec> // for QTextCodec
+
+#include "defs.h"
+#include "cet_util.h"
+#include "src/core/logging.h" // for Fatal
+
+
+#define MYNAME "cet_util"
+
+/* gpsbabel additions */
+
+void
+cet_convert_deinit()
+{
+ global_opts.codec = nullptr;
+}
+
+void
+cet_convert_init(const QString& cs_name, const int force)
+{
+ if ((force != 0) || (global_opts.codec == nullptr)) {
+ cet_convert_deinit();
+ if (cs_name.isEmpty()) { /* set default us-ascii */
+ global_opts.codec = QTextCodec::codecForName(CET_CHARSET_ASCII);
+ } else {
+ global_opts.codec = QTextCodec::codecForName(CSTR(cs_name));
+ }
+ if (!global_opts.codec) {
+ fatal(FatalMsg() << "Unsupported character set \"" << cs_name << ".");
+ }
+ }
+}
--- /dev/null
+/*
+
+ Character encoding transformation - utilities header
+
+ Copyright (C) 2005-2008 Olaf Klein, o.b.klein@gpsbabel.org
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+*/
+
+#ifndef CET_UTIL_H_INCLUDED_
+#define CET_UTIL_H_INCLUDED_
+
+#include <QString>
+#include "defs.h"
+
+
+/* gpsbabel extensions */
+
+void cet_convert_init(const QString& cs_name, int force);
+void cet_convert_deinit();
+
+#endif // CET_UTIL_H_INCLUDED_
#include <QByteArray> // for QByteArray
#include <QChar> // for QChar
#include <QString> // for QString
+#include <QTextCodec> // for QTextCodec
#include <QVector> // for QVector
#include <Qt> // for CaseInsensitive
#include <QtGlobal> // for qPrintable, foreach
#include "defs.h"
-#include "cet_util.h" // for cet_convert_init, cet_cs_vec_utf8
#include "format.h" // for Format
+#include "formspec.h" // for FormatSpecificDataList
#include "garmin_device_xml.h" // for gdx_get_info, gdx_info, gdx_file, gdx_jmp_buf
#include "garmin_fs.h" // for garmin_fs_garmin_after_read, garmin_fs_garmin_before_write
#include "garmin_tables.h" // for gt_find_icon_number_from_desc, PCX, gt_find_desc_from_icon_number
static int baud = 0;
static int categorybits;
static int receiver_must_upper = 1;
+static QTextCodec* codec{nullptr};
static Format* gpx_vec;
static const char* d103_symbol_from_icon_number(unsigned int n);
static int d103_icon_number_from_symbol(const QString& s);
+static void garmin_fs_garmin_after_read(GPS_PWay way, Waypoint* wpt, int protoid);
+static void garmin_fs_garmin_before_write(const Waypoint* wpt, GPS_PWay way, int protoid);
+static QByteArray str_from_unicode(const QString& qstr) {return codec->fromUnicode(qstr);}
+static QString str_to_unicode(const QByteArray& cstr) {return codec->toUnicode(cstr);}
static void
rw_init(const QString& fname)
{
receiver_must_upper = 1;
- const char* receiver_charset = nullptr;
+ const char* receiver_charset = CET_CHARSET_ASCII;
if (!mkshort_handle) {
mkshort_handle = mkshort_new_handle();
/*
* This used to mean something when we used cet, but these days this
- * format either use implicit QString conversions (utf8) which is
- * likely a bug, or we have hard coded QString::fromLatin1 or CSTRc.
- * So all the above detection of receiver_charset is for naught.
- * But perhaps we will use an appropriate codec based on receiver_charset
- * someday.
+ * format either uses implicit QString conversions (utf8),
+ * or we have hard coded QString::fromLatin1, CSTRc, or CSTR. These
+ * are likely bugs.
+ * However, this is still used for garmin_fs_garmin_after_read,
+ * garmin_fs_garmin_before_write.
*/
- if (receiver_charset) {
- cet_convert_init(receiver_charset, 1);
- }
+ codec = get_codec(receiver_charset);
}
static void
}
return 0;
}
+
+static void
+garmin_fs_garmin_after_read(const GPS_PWay way, Waypoint* wpt, const int protoid)
+{
+ garmin_fs_t* gmsd = garmin_fs_alloc(protoid);
+ wpt->fs.FsChainAdd(gmsd);
+
+ /* nothing happens until gmsd is allocated some lines above */
+
+ /* !!! class needs protocol specific conversion !!! (ToDo)
+ garmin_fs_t::set_wpt_class(gmsd, way[i]->wpt_class);
+ */
+ /* flagged data fields */
+ garmin_fs_t::set_display(gmsd, gt_switch_display_mode_value(way->dspl, gps_waypt_type, 1));
+ if (way->category != 0) {
+ garmin_fs_t::set_category(gmsd, way->category);
+ }
+ if (way->dst < 1.0e25f) {
+ WAYPT_SET(wpt, proximity, way->dst);
+ }
+ if (way->temperature_populated) {
+ WAYPT_SET(wpt, temperature, way->temperature);
+ }
+ if (way->dpth < 1.0e25f) {
+ WAYPT_SET(wpt, depth, way->dpth);
+ }
+ /* will copy until a null character or the end of the fixed length way field is reached, whichever comes first. */
+ garmin_fs_t::set_cc(gmsd, str_to_unicode(QByteArray(way->cc, qstrnlen(way->cc, sizeof(way->cc)))));
+ garmin_fs_t::set_city(gmsd, str_to_unicode(QByteArray(way->city, qstrnlen(way->city, sizeof(way->city)))));
+ garmin_fs_t::set_state(gmsd, str_to_unicode(QByteArray(way->state, qstrnlen(way->state, sizeof(way->state)))));
+ garmin_fs_t::set_facility(gmsd, str_to_unicode(QByteArray(way->facility, qstrnlen(way->facility, sizeof(way->facility)))));
+ garmin_fs_t::set_cross_road(gmsd, str_to_unicode(QByteArray(way->cross_road, qstrnlen(way->cross_road, sizeof(way->cross_road)))));
+ garmin_fs_t::set_addr(gmsd, str_to_unicode(QByteArray(way->addr, qstrnlen(way->addr, sizeof(way->addr)))));
+}
+
+static void
+garmin_fs_garmin_before_write(const Waypoint* wpt, GPS_PWay way, const int protoid)
+{
+ garmin_fs_t* gmsd = garmin_fs_t::find(wpt);
+
+ (void)protoid; // unused for now.
+
+ if (gmsd == nullptr) {
+ return;
+ }
+
+ /* ToDo: protocol specific conversion of class
+ way[i]->wpt_class = garmin_fs_t::get_wpt_class(gmsd, way[i]->wpt_class);
+ */
+ way->dspl = gt_switch_display_mode_value(
+ garmin_fs_t::get_display(gmsd, way->dspl), gps_waypt_type, 0);
+ way->category = garmin_fs_t::get_category(gmsd, way->category);
+ way->dpth = WAYPT_GET(wpt, depth, way->dpth);
+ way->dst = WAYPT_GET(wpt, proximity, way->dpth);
+ way->temperature = WAYPT_GET(wpt, temperature, way->temperature);
+
+ /* destination may not be null terminated, but we will fill with nulls if necessary */
+ strncpy(way->cc, str_from_unicode(garmin_fs_t::get_cc(gmsd, nullptr)).constData(), sizeof(way->cc));
+ strncpy(way->city, str_from_unicode(garmin_fs_t::get_city(gmsd, nullptr)).constData(), sizeof(way->city));
+ strncpy(way->state, str_from_unicode(garmin_fs_t::get_state(gmsd, nullptr)).constData(), sizeof(way->state));
+ strncpy(way->facility, str_from_unicode(garmin_fs_t::get_facility(gmsd, nullptr)).constData(), sizeof(way->facility));
+ strncpy(way->cross_road, str_from_unicode(garmin_fs_t::get_cross_road(gmsd, nullptr)).constData(), sizeof(way->cross_road));
+ strncpy(way->addr, str_from_unicode(garmin_fs_t::get_addr(gmsd, nullptr)).constData(), sizeof(way->addr));
+}
*/
-#include <cassert> // for assert
#include <cstdio> // for snprintf, sscanf
#include <cstdlib> // for strtod
-#include <cstring> // for strncpy
-#include <QByteArray> // for QByteArray
#include <QString> // for QString, QStringLiteral
#include <QXmlStreamWriter> // for QXmlStreamWriter
#include <Qt> // for CaseInsensitive
#include "garmin_fs.h"
#include "garmin_tables.h" // for gt_switch_display_mode_value, gt_display_mode_symbol, gt_display_mode_symbol_and_comment, gt_display_mode_symbol_and_name
#include "inifile.h" // for inifile_readstr
-#include "jeeps/gps.h" // for gps_waypt_type
#define MYNAME "garmin_fs"
garmin_fs_t::set_category(gmsd, cat);
return 1;
}
-
-void
-garmin_fs_garmin_after_read(const GPS_PWay way, Waypoint* wpt, const int protoid)
-{
- garmin_fs_t* gmsd = garmin_fs_alloc(protoid);
- wpt->fs.FsChainAdd(gmsd);
-
- /* nothing happens until gmsd is allocated some lines above */
-
- /* !!! class needs protocol specific conversion !!! (ToDo)
- garmin_fs_t::set_wpt_class(gmsd, way[i]->wpt_class);
- */
- /* flagged data fields */
- garmin_fs_t::set_display(gmsd, gt_switch_display_mode_value(way->dspl, gps_waypt_type, 1));
- if (way->category != 0) {
- garmin_fs_t::set_category(gmsd, way->category);
- }
- if (way->dst < 1.0e25f) {
- WAYPT_SET(wpt, proximity, way->dst);
- }
- if (way->temperature_populated) {
- WAYPT_SET(wpt, temperature, way->temperature);
- }
- if (way->dpth < 1.0e25f) {
- WAYPT_SET(wpt, depth, way->dpth);
- }
- // These use STRTOUNICODE which uses gobal_opts.codec.
- garmin_fs_t::set_cc(gmsd, STRTOUNICODE(QByteArray(way->cc, sizeof(way->cc)).constData()));
- garmin_fs_t::set_city(gmsd, STRTOUNICODE(QByteArray(way->city, sizeof(way->city)).constData()));
- garmin_fs_t::set_state(gmsd, STRTOUNICODE(QByteArray(way->state, sizeof(way->state)).constData()));
- garmin_fs_t::set_facility(gmsd, STRTOUNICODE(QByteArray(way->facility, sizeof(way->facility)).constData()));
- garmin_fs_t::set_cross_road(gmsd, STRTOUNICODE(QByteArray(way->cross_road, sizeof(way->cross_road)).constData()));
- garmin_fs_t::set_addr(gmsd, STRTOUNICODE(QByteArray(way->addr, sizeof(way->addr)).constData()));
-}
-
-void
-garmin_fs_garmin_before_write(const Waypoint* wpt, GPS_PWay way, const int protoid)
-{
- garmin_fs_t* gmsd = garmin_fs_t::find(wpt);
-
- (void)protoid; // unused for now.
-
- if (gmsd == nullptr) {
- return;
- }
-
- /* ToDo: protocol specific conversion of class
- way[i]->wpt_class = garmin_fs_t::get_wpt_class(gmsd, way[i]->wpt_class);
- */
- way->dspl = gt_switch_display_mode_value(
- garmin_fs_t::get_display(gmsd, way->dspl), gps_waypt_type, 0);
- way->category = garmin_fs_t::get_category(gmsd, way->category);
- way->dpth = WAYPT_GET(wpt, depth, way->dpth);
- way->dst = WAYPT_GET(wpt, proximity, way->dpth);
- way->temperature = WAYPT_GET(wpt, temperature, way->temperature);
-
- // These use STRFROMUNICODE which uses gobal_opts.codec.
- strncpy(way->cc, STRFROMUNICODE(garmin_fs_t::get_cc(gmsd, nullptr)), sizeof(way->cc));
- strncpy(way->city, STRFROMUNICODE(garmin_fs_t::get_city(gmsd, nullptr)), sizeof(way->city));
- strncpy(way->state, STRFROMUNICODE(garmin_fs_t::get_state(gmsd, nullptr)), sizeof(way->state));
- strncpy(way->facility, STRFROMUNICODE(garmin_fs_t::get_facility(gmsd, nullptr)), sizeof(way->facility));
- strncpy(way->cross_road, STRFROMUNICODE(garmin_fs_t::get_cross_road(gmsd, nullptr)), sizeof(way->cross_road));
- strncpy(way->addr, STRFROMUNICODE(garmin_fs_t::get_addr(gmsd, nullptr)), sizeof(way->addr));
-}
#include "defs.h"
#include "formspec.h" // for FsChainFind, kFsGmsd, FormatSpecificData
-#include "jeeps/gps.h"
/* this order is used by most devices */
#define GMSD_SECTION_CATEGORIES "Garmin Categories"
-void garmin_fs_garmin_after_read(GPS_PWay way, Waypoint* wpt, int protoid);
-void garmin_fs_garmin_before_write(const Waypoint* wpt, GPS_PWay way, int protoid);
-
#endif
#include <ctime> // for time, gmtime, time_t, tm
#include <memory> // for unique_ptr
-#include "defs.h" // for Waypoint, fatal, STRFROMUNICODE, le_write32, le_write16, wp_flags, warning, bounds, KPH_TO_MPS, MPH_TO_MPS, WAYPT_HAS, gpsbabel_testmode, parse_speed, WAYPT_SET, MILES_TO_METERS, MPS_TO_KPH, MPS_TO_MPH, mkgmtime, mkshort, mkshort_del_handle, mkshort_new_...
-#include "cet_util.h" // for cet_convert_init
+#include "defs.h" // for Waypoint, fatal, le_write32, le_write16, wp_flags, warning, bounds, KPH_TO_MPS, MPH_TO_MPS, WAYPT_HAS, gpsbabel_testmode, parse_speed, WAYPT_SET, MILES_TO_METERS, MPS_TO_KPH, MPS_TO_MPH, mkgmtime, mkshort, mkshort_del_handle, mkshort_new_...
#include "formspec.h" // for FormatSpecificDataList
#include "garmin_fs.h" // for garmin_fs_t, garmin_fs_alloc
#include "gbfile.h" // for gbfputint32, gbfgetint32, gbfgetint16, gbfputint16, gbfgetc, gbfputc, gbfread, gbftell, gbfwrite, gbfseek, gbfclose, gbfopen_le, gbfgetuint16, gbsize_t, gbfile
}
}
- QString result = STRTOUNICODE(string).trimmed();
+ QString result = str_to_unicode(string).trimmed();
if (GPI_DBG) {
warning("%s: \"%s\"\n", field, result.isNull() ? "<NULL>" : qPrintable(result));
}
*******************************************************************************/
void
-GarminGPIFormat::write_string(const char* str, const char long_format) const
+GarminGPIFormat::write_string(const QByteArray& str, const char long_format) const
{
- int len = strlen(str);
+ int len = str.size();
if (long_format) {
gbfputint32(len + 4, fout);
gbfwrite("EN", 1, 2, fout);
}
gbfputint16(len, fout);
- gbfwrite(str, 1, len, fout);
+ gbfwrite(str.constData(), 1, len, fout);
}
bool
res += 12; /* tag/sz/sub-sz */
res += 19; /* poi fixed size */
- res += strlen(STRFROMUNICODE(wpt->shortname));
+ res += str_from_unicode(wpt->shortname).size();
if (! opt_hide_bitmap) {
res += 10; /* tag(4) */
}
if (!str.isEmpty()) {
dt->addr = str;
dt->mask |= GPI_ADDR_ADDR;
- dt->sz += (8 + strlen(STRFROMUNICODE(dt->addr)));
+ dt->sz += (8 + str_from_unicode(dt->addr).size());
}
if ((gmsd = garmin_fs_t::find(wpt))) {
if ((dt->mask == 0) && !(dt->addr = garmin_fs_t::get_addr(gmsd, nullptr)).isEmpty()) {
dt->mask |= GPI_ADDR_ADDR;
- dt->sz += (8 + strlen(STRFROMUNICODE(dt->addr)));
+ dt->sz += (8 + str_from_unicode(dt->addr).size());
}
if (!(dt->city = garmin_fs_t::get_city(gmsd, nullptr)).isEmpty()) {
dt->mask |= GPI_ADDR_CITY;
- dt->sz += (8 + strlen(STRFROMUNICODE(dt->city)));
+ dt->sz += (8 + str_from_unicode(dt->city).size());
}
if (!(dt->country = garmin_fs_t::get_country(gmsd, nullptr)).isEmpty()) {
dt->mask |= GPI_ADDR_COUNTRY;
- dt->sz += (8 + strlen(STRFROMUNICODE(dt->country)));
+ dt->sz += (8 + str_from_unicode(dt->country).size());
}
if (!(dt->state = garmin_fs_t::get_state(gmsd, nullptr)).isEmpty()) {
dt->mask |= GPI_ADDR_STATE;
- dt->sz += (8 + strlen(STRFROMUNICODE(dt->state)));
+ dt->sz += (8 + str_from_unicode(dt->state).size());
}
if (!(dt->postal_code = garmin_fs_t::get_postal_code(gmsd, nullptr)).isEmpty()) {
dt->mask |= GPI_ADDR_POSTAL_CODE;
- dt->sz += (2 + strlen(STRFROMUNICODE(dt->postal_code))); /* short form */
+ dt->sz += (2 + str_from_unicode(dt->postal_code).size()); /* short form */
}
if (!(dt->phone_nr = garmin_fs_t::get_phone_nr(gmsd, nullptr)).isEmpty()) {
- res += (12 + 4 + strlen(STRFROMUNICODE(dt->phone_nr)));
+ res += (12 + 4 + str_from_unicode(dt->phone_nr).size());
}
}
if (dt->mask) {
}
// if (str && (strcmp(str, wpt->shortname) == 0)) str = NULL;
if (!str.isEmpty()) {
- res += (12 + 4 + strlen(STRFROMUNICODE(str)));
+ res += (12 + 4 + str_from_unicode(str).size());
}
}
}
gbfputint32(0x80002, fout);
- int s0 = s1 = 19 + strlen(STRFROMUNICODE(wpt->shortname));
+ int s0 = s1 = 19 + str_from_unicode(wpt->shortname).size();
if (! opt_hide_bitmap) {
s0 += 10; /* tag(4) */
}
if (!str.isEmpty()) {
- s0 += (12 + 4 + strlen(STRFROMUNICODE(str))); /* descr */
+ s0 += (12 + 4 + str_from_unicode(str).size()); /* descr */
}
if (dt->sz) {
s0 += (12 + dt->sz); /* address part */
}
if (!dt->phone_nr.isEmpty()) {
- s0 += (12 + 4 + strlen(STRFROMUNICODE(dt->phone_nr)));
+ s0 += (12 + 4 + str_from_unicode(dt->phone_nr).size());
}
if (dt->alerts) {
s0 += 20; /* tag(3) */
gbfputint16(1, fout); /* ? always 1 ? */
gbfputc(alerts, fout); /* seems to be 1 when extra options present */
- write_string(STRFROMUNICODE(wpt->shortname), 1);
+ write_string(str_from_unicode(wpt->shortname), 1);
if (dt->alerts) {
char flag = 0;
if (!str.isEmpty()) {
gbfputint32(0xa, fout);
- gbfputint32(strlen(STRFROMUNICODE(str)) + 8, fout); /* string + string header */
- write_string(STRFROMUNICODE(str), 1);
+ gbfputint32(str_from_unicode(str).size() + 8, fout); /* string + string header */
+ write_string(str_from_unicode(str), 1);
}
if (dt->sz) { /* gpi address */
gbfputint32(0x2, fout); /* ? always 2 ? */
gbfputint16(dt->mask, fout);
if (dt->mask & GPI_ADDR_CITY) {
- write_string(STRFROMUNICODE(dt->city), 1);
+ write_string(str_from_unicode(dt->city), 1);
}
if (dt->mask & GPI_ADDR_COUNTRY) {
- write_string(STRFROMUNICODE(dt->country), 1);
+ write_string(str_from_unicode(dt->country), 1);
}
if (dt->mask & GPI_ADDR_STATE) {
- write_string(STRFROMUNICODE(dt->state), 1);
+ write_string(str_from_unicode(dt->state), 1);
}
if (dt->mask & GPI_ADDR_POSTAL_CODE) {
- write_string(STRFROMUNICODE(dt->postal_code), 0);
+ write_string(str_from_unicode(dt->postal_code), 0);
}
if (dt->mask & GPI_ADDR_ADDR) {
- write_string(STRFROMUNICODE(dt->addr), 1);
+ write_string(str_from_unicode(dt->addr), 1);
}
}
if (!dt->phone_nr.isEmpty()) {
gbfputint32(0x8000c, fout);
- gbfputint32(strlen(STRFROMUNICODE(dt->phone_nr)) + 2 + 2, fout);
+ gbfputint32(str_from_unicode(dt->phone_nr).size() + 2 + 2, fout);
gbfputint32(0x2, fout); /* ? always 2 ? */
gbfputint16(1, fout); /* mask */
- write_string(STRFROMUNICODE(dt->phone_nr), 0);
+ write_string(str_from_unicode(dt->phone_nr), 0);
}
}
{
int sz = wdata_compute_size(wdata);
sz += 8; /* string header */
- sz += strlen(STRFROMUNICODE(QString::fromUtf8(opt_cat)));
+ sz += str_from_unicode(QString::fromUtf8(opt_cat)).size();
gbfputint32(0x80009, fout);
if ((! opt_hide_bitmap) && image_sz) {
gbfputint32(sz, fout);
}
gbfputint32(sz, fout);
- write_string(STRFROMUNICODE(QString::fromUtf8(opt_cat)), 1);
+ write_string(str_from_unicode(QString::fromUtf8(opt_cat)), 1);
wdata_write(wdata);
read_header();
if ((codepage >= 1250) && (codepage <= 1257)) {
- QString qCodecName = QStringLiteral("windows-%1").arg(codepage);
- cet_convert_init(CSTR(qCodecName), 1);
+ QByteArray qCodecName = "windows-" + QByteArray::number(codepage);
+ codec = get_codec(qCodecName);
} else if (codepage == 65001) {
- cet_convert_init("utf8", 1);
+ codec = get_codec("utf8");
} else {
fatal(MYNAME ": Unsupported code page (%d). File is likely encrypted.\n", codepage);
}
fatal(MYNAME ": Valid values are windows-1250 to windows-1257 and utf8.\n");
}
- cet_convert_init(opt_writecodec,1);
+ codec = get_codec(opt_writecodec);
units = tolower(opt_units[0]);
if ((units != 'm') && (units != 's')) {
#include <QByteArray> // for QByteArray
#include <QList> // for QList
#include <QString> // for QString
+#include <QTextCodec> // for QTextCodec
#include <QVector> // for QVector
#include <cstdint> // for int32_t, int16_t, uint16_t
void read_poi_list(int sz);
void read_poi_group(int sz, int tag);
int read_tag(const char* caller, int tag, Waypoint* wpt);
- void write_string(const char* str, char long_format) const;
+ void write_string(const QByteArray& str, char long_format) const;
static bool compare_wpt_cb(const Waypoint* a, const Waypoint* b);
static char compare_strings(const QString& s1, const QString& s2);
static writer_data_t* wdata_alloc();
void write_header() const;
void enum_waypt_cb(const Waypoint* ref) const;
static void load_bitmap_from_file(const char* fname, const unsigned char** data, int* data_sz);
+ QByteArray str_from_unicode(const QString& qstr) const {return codec->fromUnicode(qstr);}
+ QString str_to_unicode(const QByteArray& cstr) const {return codec->toUnicode(cstr);}
/* Data Members */
short_handle short_h{};
char units{};
time_t gpi_timestamp = 0;
+ QTextCodec* codec{nullptr};
};
#endif // GARMIN_GPI_H_INCLUDED_
#include <iterator> // for next
#include "defs.h" // for Waypoint, warning, fatal, route_head, UrlLink, bounds, mkshort, UrlList, unknown_alt, wp_flags, xfree, waypt_add_to_bounds, waypt_init_bounds, mkshort_del_handle, route_add_wpt, route_disp_all, waypt_bounds_valid, xmalloc, WAYPT_GET, WAYPT_SET, gb_color
-#include "cet_util.h" // for cet_convert_init
#include "formspec.h" // for FormatSpecificDataList
#include "garmin_fs.h" // for garmin_fs_t, garmin_ilink_t, garmin_fs_alloc
#include "garmin_tables.h" // for gt_waypt_class_map_point, gt_color_index_by_rgb, gt_color_value, gt_waypt_classes_e, gt_find_desc_from_icon_number, gt_find_icon_number_from_desc, gt_gdb_display_mode_symbol, gt_get_icao_country, gt_waypt_class_user_waypoint, GDB, gt_display_mode_symbol
fin = gbfopen_le(fname, "rb", MYNAME);
ftmp = gbfopen_le(nullptr, "wb", MYNAME);
read_file_header();
- /* VERSION DEPENDENT CODE */
- if (gdb_ver >= GDB_VER_UTF8) {
- cet_convert_init(CET_CHARSET_UTF8, 1);
- }
wayptq_in.clear();
wayptq_in_hidden.clear();
gdb_category = strtol(gdb_opt_bitcategory, nullptr, 0);
}
- if (gdb_ver >= GDB_VER_UTF8) {
- cet_convert_init(CET_CHARSET_UTF8, 1);
- }
-
wayptq_out.clear();
short_h = nullptr;
#include <QtGlobal> // for foreach, qPrintable
#include "defs.h"
-#include "cet_util.h" // for cet_convert_init
#include "gbfile.h" // for gbfprintf, gbfclose, gbfopen, gbfputs, gbfgetstr, gbfile
#include "src/core/datetime.h" // for DateTime
char* c;
retry:
*rec = c = gbfgetstr(file_in);
- if ((lineno++ == 0) && file_in->unicode) {
- cet_convert_init(CET_CHARSET_UTF8, 1);
- }
if (c == nullptr) {
return rec_none;
}
#endif
#include "defs.h"
-#include "cet_util.h" // for cet_convert_init, cet_convert_deinit
#include "csv_util.h" // for csv_linesplit
#include "filter.h" // for Filter
#include "filter_vecs.h" // for FilterVecs
global_opts.masked_objective |= WPTDATAMASK;
}
- cet_convert_init(ivecs->get_encode(), ivecs->get_fixed_encode()); /* init by module vec */
-
start_session(ivecs->get_name(), fname);
ivecs->rd_init(fname);
ivecs->read();
ivecs->rd_deinit();
- cet_convert_deinit();
-
did_something = true;
break;
case 'F':
global_opts.masked_objective |= WPTDATAMASK;
}
- cet_convert_init(ovecs->get_encode(), ovecs->get_fixed_encode());
-
ovecs->wr_init(ofname);
ovecs->write();
ovecs->wr_deinit();
- cet_convert_deinit();
}
break;
case 's':
/* reinitialize xcsv in case two formats that use xcsv were given */
(void) Vecs::Instance().find_vec(ivecs->get_argstring());
- cet_convert_init(ivecs->get_encode(), 1);
-
start_session(ivecs->get_name(), qargs.at(0));
ivecs->rd_init(qargs.at(0));
ivecs->read();
ivecs->rd_deinit();
- cet_convert_deinit();
-
if (qargs.size() == 2 && ovecs) {
/* reinitialize xcsv in case two formats that use xcsv were given */
(void) Vecs::Instance().find_vec(ovecs->get_argstring());
- cet_convert_init(ovecs->get_encode(), 1);
-
ovecs->wr_init(qargs.at(1));
ovecs->write();
ovecs->wr_deinit();
- cet_convert_deinit();
}
} else if (!qargs.isEmpty()) {
usage(prog_name,0);
return 0;
}
if (ovecs == nullptr) {
- cet_convert_init(CET_CHARSET_ASCII, 1);
auto waypt_disp_lambda = [&fbOutput](const Waypoint* wpt)->void {
fbOutput.waypt_disp(wpt);
};
#include "defs.h"
#include "nmea.h"
-#include "cet_util.h" // for cet_convert_init
#include "gbfile.h" // for gbfprintf, gbfflush, gbfclose, gbfopen, gbfgetstr, gbfile
#include "gbser.h" // for gbser_set_speed, gbser_flush, gbser_read_line, gbser_deinit, gbser_init, gbser_write
#include "jeeps/gpsmath.h" // for GPS_Lookup_Datum_Index, GPS_Math_Known_Datum_To_WGS84_M
while ((ibuf = gbfgetstr(file_in))) {
line++;
- if ((line == 0) & file_in->unicode) {
- cet_convert_init(CET_CHARSET_UTF8, 1);
- }
-
if ((line == 0) && (case_ignore_strncmp(ibuf, "@SonyGPS/ver", 12) == 0)) {
/* special hack for Sony GPS-CS1 files:
they are fully (?) nmea compatible, but come with a header line like
return x.i;
}
+QTextCodec* get_codec(const QByteArray& cs_name)
+{
+ QTextCodec* codec = QTextCodec::codecForName(cs_name);
+ if (codec == nullptr) {
+ fatal(FatalMsg().nospace() << "Unsupported character set " << cs_name << ".");
+ }
+ return codec;
+}
+
void
list_codecs()
{